import numpy as np

import base_api

obj = base_api.BaseAPI()
obj.devInit()
print('Dev init')

chipNum = 0
obj.selectChip(chipNum)
print('Chip Num = %d' % chipNum)

rowIdx = 0
colIdx = 0

ret = 0

print('*************Forming*************')
for _ in range(3):
    ret = obj.readOneCell(rowIdx, colIdx, 'POS')
    if ret == 8:
        obj.formOneCell(rowIdx, colIdx, 'POS', 4.55, 1.87, 1000000)

ret = obj.readOneCell(rowIdx, colIdx, 'POS')
print('The result of readOneCell() is %d' % ret)
ret = obj.calcOneCell(rowIdx, colIdx, 'POS')
print('The result of calcOneCell() is %d' % ret)

print('*************Set*************')
obj.setOneCell(rowIdx, colIdx, 'POS', 2, 3, 500)
ret = obj.readOneCell(rowIdx, colIdx, 'POS')
print('The result of readOneCell() is %d' % ret)
ret = obj.calcOneCell(rowIdx, colIdx, 'POS')
print('The result of calcOneCell() is %d' % ret)

print('*************Reset*************')
obj.resetOneCell(rowIdx, colIdx, 'POS', 2.5, 3.5, 500)
ret = obj.readOneCell(rowIdx, colIdx, 'POS')
print('The result of readOneCell() is %d' % ret)
ret = obj.calcOneCell(rowIdx, colIdx, 'POS')
print('The result of calcOneCell() is %d' % ret)

print('*************Map*************')
obj.mapSingleDevice_2T2R(rowIdx, colIdx, 5)
ret = obj.readOneCell(rowIdx, colIdx, 'POS')
print('The result of readOneCell() is %d' % ret)
ret = obj.calcOneCell(rowIdx, colIdx, 'POS')
print('The result of calcOneCell() is %d' % ret)

print('*************calcArray*************')
rowInput = np.random.randint(0, 2, (3, 20), dtype='uint8')
ret = obj.calcArray(rowInput, 0, 0, 10)
print(ret)
